RFW.HUDS = {
}

addHook("PlayerThink", function(p)
	hud.disable("rings")
	hud.disable("time")
	hud.disable("score")
	hud.disable("lives")
end)

function RFW.AddHud(name, func)
	local constant = #RFW.HUDS+1
	RFW.HUDS[constant] = {name, func}
	return constant
end

COM_AddCommand("partime_style", function (p, a)
	if a == "1" then
		CONS_Printf(p, "Par Time will use Tics")
		p.timedisplayoption = 1
	else
		CONS_Printf(p, "Par Time will use Seconds + Miliseconds")
		p.timedisplayoption = 0
	end
end)

COM_AddCommand("partime_style2", function (p, a)
	if a == "1" then
		CONS_Printf(p, "Par Time will use Tics")
		p.timedisplayoption = 1
	else
		CONS_Printf(p, "Par Time will use Seconds + Miliseconds")
		p.timedisplayoption = 0
	end
end, COM_SPLITSCREEN)

local function stupidbullshit(timer)
	if timer < 10 then return "0"
	else return "" end
end

local function ticstomsms(tics)
	return stupidbullshit(G_TicsToMinutes(tics, true)) .. G_TicsToMinutes(tics, true) .. ":" .. stupidbullshit(G_TicsToSeconds(tics)) .. G_TicsToSeconds(tics) .. "." .. stupidbullshit(G_TicsToCentiseconds(tics)) .. G_TicsToCentiseconds(tics)
end

RFW.AddHud("Fullscreen", function(v, p, c)
	local bcenterx = 160 - ((v.width()/(v.dupx() * 2) - 160))
	local bcentery = 100 + ((v.height()/(v.dupy() * 2) - 100)) 
	local currentweapon = (p.slot ~= nil and p.weapon ~= nil) and RFW.Weapons[p.slot][p.weapon]or nil
	local ammotype = RFW.Weapons[p.slot][p.weapon]["AmmoType"]
	
	//Numbers
	v.drawLevelTitle(4+2+16+2, 200-2-24, p.phealth, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER)
	v.drawLevelTitle(4+2+16+2, 200-2-24-2-26, p.parmor, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER)
	v.drawString(4+2+16+2+v.levelTitleWidth(p.parmor), 200-2-24-2-26, p.papval, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER)
	if ammotype ~= 0 then
		v.drawLevelTitle(320-6-16-2-v.levelTitleWidth(p.ammolist[ammotype]), 200-2-24, p.ammolist[ammotype], V_SNAPTORIGHT|V_SNAPTOBOTTOM|V_PERPLAYER)
	else
		v.drawLevelTitle(320-6-16-2-v.levelTitleWidth("Inf"), 200-2-24, "Inf", V_SNAPTORIGHT|V_SNAPTOBOTTOM|V_PERPLAYER)
	end
	//Icons
	v.draw(4+2, 200-23, v.cachePatch("HEALTHICO"), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_PERPLAYER, v.getColormap(TC_RAINBOW, p.mo.color))
	v.draw(4+2, 200-23-2-26, v.cachePatch("ARMORICO"), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_PERPLAYER, v.getColormap(TC_RAINBOW, p.mo.color))
	v.draw(320-6-16, 200-23, v.cachePatch("AMMOICO"), V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER, v.getColormap(TC_RAINBOW, p.mo.color))
	//
	if multiplayer then
		v.drawString(2, 200-76, p.personalkillcount, V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_PERPLAYER, "left")
	end
	v.drawString(2, 200-66, RFW.killcount.."/"..RFW.enemycount, V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_PERPLAYER, "left")
	if p.timedisplayoption == 1 then
		if multiplayer then
			v.drawString(320-2, 200-48, p.realtime, V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER, "right")
			local partime = (mapheaderinfo[gamemap].partime) and tonumber(mapheaderinfo[gamemap].partime) or nil
			v.drawString(320-2, 200-38, leveltime..((partime ~= nil) and "/"..partime or ""), V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER, "right")
		else
			local partime = (mapheaderinfo[gamemap].partime) and tonumber(mapheaderinfo[gamemap].partime) or nil
			v.drawString(320-2, 200-38, p.realtime..((partime ~= nil) and "/"..partime or ""), V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER, "right")
		end
	else
		if multiplayer then
			v.drawString(320-2, 200-48, ticstomsms(p.realtime), V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER, "right")
			local partime = (mapheaderinfo[gamemap].partime) and tonumber(mapheaderinfo[gamemap].partime) or nil
			v.drawString(320-2, 200-38, ticstomsms(leveltime)..((partime ~= nil) and "/"..ticstomsms(partime) or ""), V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER, "right")
		else
			local partime = (mapheaderinfo[gamemap].partime) and tonumber(mapheaderinfo[gamemap].partime) or nil
			v.drawString(320-2, 200-38, ticstomsms(p.realtime)..((partime ~= nil) and "/"..ticstomsms(partime) or ""), V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER, "right")
		end
	end
	if multiplayer then
		if p.weaponstate == "Lower" then
			//local weaponname = ((p.switchslot and p.switchto) and (RFW.Weapons[p.switchslot][p.switchto]["Name"] or "Unidentified Weapon"))
			v.drawString(320-2, 200-58, tostring(RFW.Weapons[p.switchslot][p.switchto]["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|V_50TRANS|(p.ctfteam == 1 and V_REDMAP or p.ctfteam == 2 and V_BLUEMAP or V_YELLOWMAP), "right")
		elseif p.weaponstate == "Raise" then
			v.drawString(320-2, 200-58, tostring(currentweapon["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|V_50TRANS|(p.ctfteam == 1 and V_REDMAP or p.ctfteam == 2 and V_BLUEMAP or V_YELLOWMAP), "right")
		end
		if p.weaponstate ~= "Lower" and p.weaponstate ~= "Raise" and c.chase then
			v.drawString(320-2, 200-58, tostring(currentweapon["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|V_20TRANS, "right")
		end
	else
		if p.weaponstate == "Lower" then
			//local weaponname = ((p.switchslot and p.switchto) and (RFW.Weapons[p.switchslot][p.switchto]["Name"] or "Unidentified Weapon"))
			v.drawString(320-2, 200-48, tostring(RFW.Weapons[p.switchslot][p.switchto]["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|V_50TRANS|(p.ctfteam == 1 and V_REDMAP or p.ctfteam == 2 and V_BLUEMAP or V_YELLOWMAP), "right")
		elseif p.weaponstate == "Raise" then
			v.drawString(320-2, 200-48, tostring(currentweapon["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|V_50TRANS|(p.ctfteam == 1 and V_REDMAP or p.ctfteam == 2 and V_BLUEMAP or V_YELLOWMAP), "right")
		end
		if p.weaponstate ~= "Lower" and p.weaponstate ~= "Raise" and c.chase then
			v.drawString(320-2, 200-48, tostring(currentweapon["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|V_20TRANS, "right")
		end
	end
end)

RFW.AddHud("Modern", function(v, p, c)
	local bcenterx = 160 - ((v.width()/(v.dupx() * 2) - 160))
	local bcentery = 100 + ((v.height()/(v.dupy() * 2) - 100)) 
	local currentweapon = (p.slot ~= nil and p.weapon ~= nil) and RFW.Weapons[p.slot][p.weapon]or nil
	local ammotype = RFW.Weapons[p.slot][p.weapon]["AmmoType"]
	
	//Bars
	v.drawFill(2, 200-2-26, 104, 26, 24|V_50TRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER)
	v.drawFill(2, 200-2-26-2-26, 104, 26, 24|V_50TRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER)
	v.drawFill(320-106, 200-2-26, 104, 26, 24|V_50TRANS|V_SNAPTORIGHT|V_SNAPTOBOTTOM|V_PERPLAYER)
	//v.drawFill(4, 200-2-24, 100, 22, 24|V_20TRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER)
	//v.drawFill(4, 200-2-24-2-26, 100, 22, 24|V_20TRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER)
	//v.drawFill(320-104, 200-2-24, 100, 22, 24|V_20TRANS|V_SNAPTORIGHT|V_SNAPTOBOTTOM|V_PERPLAYER)
	v.drawFill(4, 200-2-24, min(p.phealth, 100), 22, 113|V_20TRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER)
	v.drawFill(4, 200-2-24-2-26, min(p.parmor, 100), 22, 113|V_20TRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER)
	if p.phealth > 100 then
		v.drawFill(4, 200-2-24, min(p.phealth-100, 100), 22, 132|V_20TRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER)
	end
	if p.parmor > 100 then
		v.drawFill(4, 200-2-24-2-26, min(p.parmor-100, 100), 22, 132|V_20TRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER)
	end
	if p.parmor > 200 then
		v.drawFill(4, 200-2-24-2-26, min(p.parmor-200, 100), 22, 72|V_20TRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER)
	end
	if ammotype ~= 0 then
		v.drawFill(320-4-min(p.ammolist[ammotype]*100/RFW.Ammoids[ammotype][2], 100), 200-2-24, min(p.ammolist[ammotype]*100/RFW.Ammoids[ammotype][2], 100), 22, 113|V_20TRANS|V_SNAPTORIGHT|V_SNAPTOBOTTOM|V_PERPLAYER)
	end
	//Numbers
	v.drawLevelTitle(4+2+16+2, 200-2-24, p.phealth, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER)
	v.drawLevelTitle(4+2+16+2, 200-2-24-2-26, p.parmor, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER)
	v.drawString(4+2+16+2+v.levelTitleWidth(p.parmor), 200-2-24-2-26, p.papval, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER)
	if ammotype ~= 0 then
		v.drawLevelTitle(320-6-16-2-v.levelTitleWidth(p.ammolist[ammotype]), 200-2-24, p.ammolist[ammotype], V_SNAPTORIGHT|V_SNAPTOBOTTOM|V_PERPLAYER)
	else
		v.drawLevelTitle(320-6-16-2-v.levelTitleWidth("Inf"), 200-2-24, "Inf", V_SNAPTORIGHT|V_SNAPTOBOTTOM|V_PERPLAYER)
	end
	//Icons
	v.draw(4+2, 200-23, v.cachePatch("HEALTHICO"), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_PERPLAYER, v.getColormap(TC_RAINBOW, p.mo.color))
	v.draw(4+2, 200-23-2-26, v.cachePatch("ARMORICO"), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_PERPLAYER, v.getColormap(TC_RAINBOW, p.mo.color))
	v.draw(320-6-16, 200-23, v.cachePatch("AMMOICO"), V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER, v.getColormap(TC_RAINBOW, p.mo.color))
	//
	//v.drawString(2, 200-66, p.score, V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_PERPLAYER, "left")
	if multiplayer then
		v.drawString(2, 200-76, p.personalkillcount, V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_PERPLAYER, "left")
	end
	v.drawString(2, 200-66, RFW.killcount.."/"..RFW.enemycount, V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_PERPLAYER, "left")
	if p.timedisplayoption == 1 then
		if multiplayer then
			v.drawString(320-2, 200-48, p.realtime, V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER, "right")
			local partime = (mapheaderinfo[gamemap].partime) and tonumber(mapheaderinfo[gamemap].partime) or nil
			v.drawString(320-2, 200-38, leveltime..((partime ~= nil) and "/"..partime or ""), V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER, "right")
		else
			local partime = (mapheaderinfo[gamemap].partime) and tonumber(mapheaderinfo[gamemap].partime) or nil
			v.drawString(320-2, 200-38, p.realtime..((partime ~= nil) and "/"..partime or ""), V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER, "right")
		end
	else
		if multiplayer then
			v.drawString(320-2, 200-48, ticstomsms(p.realtime), V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER, "right")
			local partime = (mapheaderinfo[gamemap].partime) and tonumber(mapheaderinfo[gamemap].partime) or nil
			v.drawString(320-2, 200-38, ticstomsms(leveltime)..((partime ~= nil) and "/"..ticstomsms(partime) or ""), V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER, "right")
		else
			local partime = (mapheaderinfo[gamemap].partime) and tonumber(mapheaderinfo[gamemap].partime) or nil
			v.drawString(320-2, 200-38, ticstomsms(p.realtime)..((partime ~= nil) and "/"..ticstomsms(partime) or ""), V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER, "right")
		end
	end
	if multiplayer then
		if p.weaponstate == "Lower" then
			//local weaponname = ((p.switchslot and p.switchto) and (RFW.Weapons[p.switchslot][p.switchto]["Name"] or "Unidentified Weapon"))
			v.drawString(320-2, 200-58, tostring(RFW.Weapons[p.switchslot][p.switchto]["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|V_50TRANS|(p.ctfteam == 1 and V_REDMAP or p.ctfteam == 2 and V_BLUEMAP or V_YELLOWMAP), "right")
		elseif p.weaponstate == "Raise" then
			v.drawString(320-2, 200-58, tostring(currentweapon["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|V_50TRANS|(p.ctfteam == 1 and V_REDMAP or p.ctfteam == 2 and V_BLUEMAP or V_YELLOWMAP), "right")
		end
		if p.weaponstate ~= "Lower" and p.weaponstate ~= "Raise" and c.chase then
			v.drawString(320-2, 200-58, tostring(currentweapon["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|V_20TRANS, "right")
		end
	else
		if p.weaponstate == "Lower" then
			//local weaponname = ((p.switchslot and p.switchto) and (RFW.Weapons[p.switchslot][p.switchto]["Name"] or "Unidentified Weapon"))
			v.drawString(320-2, 200-48, tostring(RFW.Weapons[p.switchslot][p.switchto]["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|V_50TRANS|(p.ctfteam == 1 and V_REDMAP or p.ctfteam == 2 and V_BLUEMAP or V_YELLOWMAP), "right")
		elseif p.weaponstate == "Raise" then
			v.drawString(320-2, 200-48, tostring(currentweapon["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|V_50TRANS|(p.ctfteam == 1 and V_REDMAP or p.ctfteam == 2 and V_BLUEMAP or V_YELLOWMAP), "right")
		end
		if p.weaponstate ~= "Lower" and p.weaponstate ~= "Raise" and c.chase then
			v.drawString(320-2, 200-48, tostring(currentweapon["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|V_20TRANS, "right")
		end
	end
end)

RFW.AddHud("Classic", function(v, p, c)
	local bcenterx = 160 - ((v.width()/(v.dupx() * 2) - 160))
	local bcentery = 100 + ((v.height()/(v.dupy() * 2) - 100)) 
	local hpcolor = V_GREENMAP
	local apcolor = V_GRAYMAP
	local currentweapon = (p.slot ~= nil and p.weapon ~= nil) and RFW.Weapons[p.slot][p.weapon]or nil
	
	local ammotype = RFW.Weapons[p.slot][p.weapon]["AmmoType"]
	if ammotype ~= 0 then
		v.drawString(bcenterx, 160, tostring(p.ammolist[ammotype]), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER, "center")
	end
	if p.weaponstate == "Lower" then
		//local weaponname = ((p.switchslot and p.switchto) and (RFW.Weapons[p.switchslot][p.switchto]["Name"] or "Unidentified Weapon"))
		v.drawString(bcenterx, 168, tostring(RFW.Weapons[p.switchslot][p.switchto]["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|V_50TRANS|(p.ctfteam == 1 and V_REDMAP or p.ctfteam == 2 and V_BLUEMAP or V_YELLOWMAP), "small-center")
	elseif p.weaponstate == "Raise" then
		v.drawString(bcenterx, 168, tostring(currentweapon["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|V_50TRANS|(p.ctfteam == 1 and V_REDMAP or p.ctfteam == 2 and V_BLUEMAP or V_YELLOWMAP), "small-center")
	end
	if p.weaponstate ~= "Lower" and p.weaponstate ~= "Raise" and c.chase then
		v.drawString(bcenterx, 168, tostring(currentweapon["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|V_20TRANS, "small-center")
	end
	
	if not p.ctfteam then
		if p.phealth <= RFW.MHealth * 1/5 then
			hpcolor = V_REDMAP
		elseif p.phealth <= RFW.MHealth * 2/5 then
			hpcolor = V_ORANGEMAP
		elseif p.phealth <= RFW.MHealth * 3/5 then
			hpcolor = V_YELLOWMAP
		elseif p.phealth <= RFW.MHealth * 4/5 then
			hpcolor = V_PERIDOTMAP
		end
		if p.phealth >= RFW.MHealth * 9/5 then
			hpcolor = V_BLUEMAP
		elseif p.phealth >= RFW.MHealth * 8/5 then
			hpcolor = V_AZUREMAP
		elseif p.phealth >= RFW.MHealth * 7/5 then
			hpcolor = V_SKYMAP
		elseif p.phealth > RFW.MHealth then
			hpcolor = V_AQUAMAP
		end
	else
		hpcolor = p.ctfteam == 1 and V_REDMAP or p.ctfteam == 2 and V_BLUEMAP
	end

	if not p.ctfteam then
		if p.papval > 0 then
			apcolor = V_PERIDOTMAP
			if p.papval > 50 then
				apcolor = V_REDMAP
			elseif p.papval > 25 then
				apcolor = V_BLUEMAP
			end
		end
	else
		apcolor = p.ctfteam == 1 and V_REDMAP or p.ctfteam == 2 and V_BLUEMAP
	end
	
	v.drawString(bcenterx - 36, 160, tostring(p.phealth), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|hpcolor, "center")
	v.drawString(bcenterx + 36, 160, tostring(p.parmor), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|apcolor, "center")
	local protoffset = v.stringWidth(p.parmor, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|apcolor)/2
	local pvcolor = apcolor == V_GRAYMAP and V_INVERTMAP or apcolor
	v.drawString(bcenterx + 36 + protoffset, 164, tostring(p.papval), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|apcolor, "small")
	
	if p.timedisplayoption == 1 then
		local partime = (mapheaderinfo[gamemap].partime) and tonumber(mapheaderinfo[gamemap].partime) or nil
		v.drawString(0, 192, p.realtime..((partime ~= nil) and "/"..partime or ""), (p.ctfteam == 1 and V_REDMAP or V_BLUEMAP)|V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_PERPLAYER, "left")
	else
		local partime = (mapheaderinfo[gamemap].partime) and tonumber(mapheaderinfo[gamemap].partime) or nil
		v.drawString(0, 192, ticstomsms(p.realtime)..((partime ~= nil) and "/"..ticstomsms(partime) or ""), (p.ctfteam == 1 and V_REDMAP or V_BLUEMAP)|V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_PERPLAYER, "thin")
	end
	v.drawString(0, 184, p.personalkillcount, (p.ctfteam == 2 and V_BLUEMAP or V_REDMAP)|V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_PERPLAYER, "left")
end)

RFW.AddHud("Pro", function(v, p, c)
	local bcenterx = 160 - ((v.width()/(v.dupx() * 2) - 160))
	local bcentery = 100 + ((v.height()/(v.dupy() * 2) - 100)) 
	local hpcolor = V_GREENMAP
	local apcolor = V_GRAYMAP
	local currentweapon = (p.slot ~= nil and p.weapon ~= nil) and RFW.Weapons[p.slot][p.weapon]or nil
	local textcol = skincolors[p.mo.color].chatcolor
	
	local ammotype = RFW.Weapons[p.slot][p.weapon]["AmmoType"]
	//if ammotype ~= 0 then
		v.drawString(160, 124, ammotype ~= 0 and tostring(p.ammolist[ammotype]) or "inf", (textcol == 0 and V_INVERTMAP or 0)|V_ALLOWLOWERCASE|V_PERPLAYER|V_50TRANS, "thin-center")
	//end
	if p.weaponstate == "Lower" then
		//local weaponname = ((p.switchslot and p.switchto) and (RFW.Weapons[p.switchslot][p.switchto]["Name"] or "Unidentified Weapon"))
		v.drawString(160, 132, tostring(RFW.Weapons[p.switchslot][p.switchto]["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_PERPLAYER|V_50TRANS|textcol, "small-center")
	elseif p.weaponstate == "Raise" then
		v.drawString(160, 132, tostring(currentweapon["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_PERPLAYER|V_50TRANS|textcol, "small-center")
	end
	if p.weaponstate ~= "Lower" and p.weaponstate ~= "Raise" then
		v.drawString(160, 132, tostring(currentweapon["WeaponName"] or "Unidentified Weapon"), (textcol == 0 and V_INVERTMAP or 0)|V_ALLOWLOWERCASE|V_PERPLAYER|V_50TRANS, "small-center")
	end
	
	local ammolen = v.stringWidth((ammotype ~= 0 and tostring(p.ammolist[ammotype]) or "inf"), V_ALLOWLOWERCASE|V_PERPLAYER, "thin")
	v.drawString(160 - ammolen/2, 124, tostring(p.phealth), V_ALLOWLOWERCASE|V_PERPLAYER|V_50TRANS|textcol, "thin-right")
	v.drawString(160 + ammolen/2, 124, tostring(p.parmor), V_ALLOWLOWERCASE|V_PERPLAYER|V_50TRANS|textcol, "thin")
	local protoffset = v.stringWidth(p.parmor, V_ALLOWLOWERCASE|V_PERPLAYER|V_50TRANS|textcol, "thin")
	//local pvcolor = apcolor == V_GRAYMAP and V_INVERTMAP or apcolor
	v.drawString(160 + ammolen/2 + protoffset, 128, tostring(p.papval), V_ALLOWLOWERCASE|V_PERPLAYER|V_50TRANS|textcol, "small")
	
	if p.timedisplayoption == 1 then
		local partime = (mapheaderinfo[gamemap].partime) and tonumber(mapheaderinfo[gamemap].partime) or nil
		v.drawString(160, 144, p.realtime..((partime ~= nil) and "/"..partime or ""), textcol|V_50TRANS|V_PERPLAYER, "thin-center")
	else
		local partime = (mapheaderinfo[gamemap].partime) and tonumber(mapheaderinfo[gamemap].partime) or nil
		v.drawString(160, 144, ticstomsms(p.realtime)..((partime ~= nil) and "/"..ticstomsms(partime) or ""), textcol|V_50TRANS|V_PERPLAYER, "thin-center")
	end
	v.drawString(160, 136, p.personalkillcount, (textcol == 0 and V_INVERTMAP or 0)|V_50TRANS|V_PERPLAYER, "thin-center")
end)

freeslot("SPR2_UBDY")

spr2defaults[SPR2_UBDY] = SPR2_STND

RFW.AddHud("UT99", function(v, p, c)
	local bcenterx = 160 - ((v.width()/(v.dupx() * 2) - 160))
	local bcentery = 100 + ((v.height()/(v.dupy() * 2) - 100)) 
	local currentweapon = (p.slot ~= nil and p.weapon ~= nil) and RFW.Weapons[p.slot][p.weapon]or nil
	local ammotype = RFW.Weapons[p.slot][p.weapon]["AmmoType"]
	
	local background = v.cachePatch("UTBACK")
	local body = v.getSprite2Patch(p.mo.skin, "UBDY", p.powers[pw_super] and true or false, 0, 0) or v.getSprite2Patch(p.mo.skin, "STND", false, 0, 0)
	//local body = v.getSprite2Patch(p.mo.skin, "XTRA", false, 2)
	local armoricon = v.cachePatch("UTAPIC")
	local healthicon = v.cachePatch("UTHPIC")
	local woffset = (leveltime/2)%7
	
	//backgrounds
	v.drawStretched(270*FU, 182*FU, FU/2, FU/2, background, V_50TRANS|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER, v.getColormap(TC_RAINBOW, p.mo.color))
	v.drawStretched(265*FU-18*3*FU/2, 0, FU/2, FU/2, background, V_50TRANS|V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER, v.getColormap(TC_RAINBOW, p.mo.color))
	v.drawStretched(265*FU-18*3*FU/2, 18*FU, FU/2, FU/2, background, V_50TRANS|V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER, v.getColormap(TC_RAINBOW, (p.phealth >= 50) and p.mo.color or woffset))
	v.drawStretched(0, 182*FU, FU/2, FU/2, background, V_50TRANS|V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_PERPLAYER, v.getColormap(TC_RAINBOW, p.mo.color))
	//ammo
	if ammotype ~= 0 then
		v.drawString(301, 187, tostring(p.ammolist[ammotype]), V_ALLOWLOWERCASE|V_40TRANS|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER, "right")
	end
	v.drawStretched(303*FU, 183*FU, FU/4, FU/4, v.cachePatch("UTAMIC"), V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER, v.getColormap(TC_RAINBOW, p.mo.color))
	//score
	v.drawString(19, 187, tostring(p.personalkillcount), V_ALLOWLOWERCASE|V_40TRANS|V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_PERPLAYER, "thin")
	v.drawStretched(1*FU, 183*FU, FU/4, FU/4, v.cachePatch("UTSCOR"), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_PERPLAYER, v.getColormap(TC_RAINBOW, p.mo.color))
	//player icon
	v.drawStretched(318*FU-18*3*FU/4, 6*FU+26*3*FU/2, 3*FU/4, 3*FU/4, body, V_50TRANS|V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER, v.getColormap(TC_RAINBOW, p.mo.color))
	//armor icon
	v.drawStretched(317*FU-18*3*FU/4-armoricon.width*FU/2, -7*FU+armoricon.height*FU/8, FU/4, FU/4, armoricon, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER, v.getColormap(TC_RAINBOW, p.mo.color))
	//health icon
	v.drawStretched(317*FU-18*3*FU/4-healthicon.width*FU/2, -5*FU+armoricon.height*FU/4+healthicon.height*FU/8, FU/4, FU/4, healthicon, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER, v.getColormap(TC_RAINBOW, (p.phealth >= 50) and p.mo.color or woffset))
	//armor and health
	v.drawString(315-18*3/4-armoricon.width/2, -3+armoricon.height/8, tostring(p.parmor), V_ALLOWLOWERCASE|V_40TRANS|V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER, "right")
	v.drawString(315-18*3/4-healthicon.width/2, -1+armoricon.height/4+healthicon.height/8, tostring(p.phealth), V_ALLOWLOWERCASE|V_40TRANS|V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER, "right")
	/*if p.weaponstate == "Lower" then
		//local weaponname = ((p.switchslot and p.switchto) and (RFW.Weapons[p.switchslot][p.switchto]["Name"] or "Unidentified Weapon"))
		v.drawString(bcenterx, 168, tostring(RFW.Weapons[p.switchslot][p.switchto]["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|V_50TRANS|(p.ctfteam == 1 and V_REDMAP or p.ctfteam == 2 and V_BLUEMAP or V_YELLOWMAP), "small-center")
	elseif p.weaponstate == "Raise" then
		v.drawString(bcenterx, 168, tostring(currentweapon["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|V_50TRANS|(p.ctfteam == 1 and V_REDMAP or p.ctfteam == 2 and V_BLUEMAP or V_YELLOWMAP), "small-center")
	end
	if p.weaponstate ~= "Lower" and p.weaponstate ~= "Raise" and c.chase then
		v.drawString(bcenterx, 168, tostring(currentweapon["WeaponName"] or "Unidentified Weapon"), V_ALLOWLOWERCASE|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_PERPLAYER|V_20TRANS, "small-center")
	end*/
	
	if p.timedisplayoption == 1 then
		local partime = (mapheaderinfo[gamemap].partime) and tonumber(mapheaderinfo[gamemap].partime) or nil
		v.drawString(160, 0, p.realtime..((partime ~= nil) and "/"..partime or ""), (p.ctfteam == 1 and V_REDMAP or p.ctfteam == 1 and V_BLUEMAP or 0)|V_SNAPTOTOP|V_PERPLAYER, "center")
	else
		local partime = (mapheaderinfo[gamemap].partime) and tonumber(mapheaderinfo[gamemap].partime) or nil
		v.drawString(160, 0, ticstomsms(p.realtime)..((partime ~= nil) and "/"..ticstomsms(partime) or ""), (p.ctfteam == 1 and V_REDMAP or p.ctfteam == 1 and V_BLUEMAP or 0)|V_SNAPTOTOP|V_PERPLAYER, "thin-center")
	end
end)

addHook("PlayerThink", function(p)
	if p.hudstyle == nil then
		p.hudstyle = 1
	end
end)

COM_AddCommand("hudstyle", function(p, slot)
	if slot == nil or tonumber(slot) == nil or RFW.HUDS[tonumber(slot)] == nil then
		for i = 1, #RFW.HUDS do
			CONS_Printf(p, i .. " - " .. RFW.HUDS[i][1])
		end
	return
	else
		local nslot = tonumber(slot)
		CONS_Printf(p, "Selected HUD style " .. nslot .. ": " .. RFW.HUDS[nslot][1])
		p.hudstyle = nslot
	end
end)

COM_AddCommand("hudstyle2", function(p, slot)
	if slot == nil or tonumber(slot) == nil or RFW.HUDS[tonumber(slot)] == nil then
		for i = 1, #RFW.HUDS do
			CONS_Printf(p, i .. " - " .. RFW.HUDS[i][1])
		end
	return
	else
		local nslot = tonumber(slot)
		CONS_Printf(p, "Selected HUD style " .. nslot .. ": " .. RFW.HUDS[nslot][1])
		p.hudstyle = nslot
	end
end, COM_SPLITSCREEN)

/*COM_AddCommand("rfw_crosshair", function(p, slot)
	if slot == nil or tonumber(slot) == nil or RFW.HUDS[tonumber(slot)] == nil then
		for i = 1, #RFW.HUDS do
			CONS_Printf(p, i .. " - " .. RFW.HUDS[i][1])
		end
	return
	else
		local nslot = tonumber(slot)
		CONS_Printf(p, "Selected HUD style " .. nslot .. ": " .. RFW.HUDS[nslot][1])
		p.hudstyle = nslot
	end
end)

COM_AddCommand("rfw_crosshair2", function(p, slot)
	if slot == nil or tonumber(slot) == nil or RFW.HUDS[tonumber(slot)] == nil then
		for i = 1, #RFW.HUDS do
			CONS_Printf(p, i .. " - " .. RFW.HUDS[i][1])
		end
	return
	else
		local nslot = tonumber(slot)
		CONS_Printf(p, "Selected HUD style " .. nslot .. ": " .. RFW.HUDS[nslot][1])
		p.hudstyle = nslot
	end
end, COM_SPLITSCREEN)*/

hud.add(function(v, p, c)
	if p.gotflag then
		local bcenterx = 160 - ((v.width()/(v.dupx() * 2) - 160))
		local bcentery = 100 + ((v.height()/(v.dupy() * 2) - 100))
		local coloroffset = FixedInt(sin(FixedAngle(3*leveltime*FU/2))*15/2+(15*FU/2)+FU/2)
		v.drawFill(0, 0, 4, splitscreen and v.height()/3 or v.height(), (p.gotflag == 1 and 32 or 144) + coloroffset|V_PERPLAYER|V_SNAPTOLEFT|V_SNAPTOTOP)
		v.drawFill(320-4, 0, 4, splitscreen and v.height()/3 or v.height(), (p.gotflag == 1 and 32 or 144) + coloroffset|V_PERPLAYER|V_SNAPTORIGHT|V_SNAPTOTOP)
		v.drawFill(4, 0, v.width()-8, 4, (p.gotflag == 1 and 32 or 144) + coloroffset|V_PERPLAYER|V_SNAPTOLEFT|V_SNAPTOTOP)
		v.drawFill(4, 200-4, v.width()-8, 4, (p.gotflag == 1 and 32 or 144) + coloroffset|V_PERPLAYER|V_SNAPTOLEFT|V_SNAPTOBOTTOM)
	end
	
	//v.drawStretched(160*FU, 100*FU, FU/5, FU/5, v.cachePatch("XHAIR3"), V_50TRANS|V_PERPLAYER)
	
	if p.hudstyle ~= nil then
		RFW.HUDS[p.hudstyle][2](v, p, c)
	else
		RFW.HUDS[1][2](v, p, c)
	end
end, "game")
